//
//  TourPlaceViewController.m
//  EDPS
//
//  Created by Neil on 15/11/27.
//  Copyright © 2015年 张维扬. All rights reserved.
//

#import "TourPlaceViewController.h"
#import "TourPlaceCollectionViewCell.h"
#import "TourPlaceTableViewCell.h"

@interface TourPlaceViewController ()<UICollectionViewDataSource, UICollectionViewDelegate, UITableViewDelegate, UITableViewDataSource>

// CollectionView
@property (nonatomic, retain) UICollectionView *collectionView;

@property (nonatomic, retain) NSMutableArray *buttonArr;

@property (nonatomic, retain) NSMutableArray *titleArr;

@end

@implementation TourPlaceViewController

- (void)viewDidAppear:(BOOL)animated{
    [super viewDidAppear:animated];
    self.navigationController.navigationBarHidden = NO;
}
- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.view.backgroundColor = [UIColor whiteColor];
    self.navigationItem.title = @"旅行地点";
    
    
    [self creatCollectionView];
    
}

#pragma mark - 菜单scrollView
- (void)creatScrollView
{
    UIScrollView *menu = [[UIScrollView alloc]initWithFrame:CGRectMake(0, 64, self.view.frame.size.width, 40)];
    
    [self.view addSubview:menu];
    
//    menu.pagingEnabled =YES;
    menu.bounces = NO;
    menu.showsHorizontalScrollIndicator = NO;  //横向
    menu.showsVerticalScrollIndicator = NO;   // 纵向s
    menu.contentSize = CGSizeMake((ScreenWidth / 5) * 6, 0);
    menu.backgroundColor = [UIColor whiteColor];
    self.buttonArr = [NSMutableArray array];
    self.titleArr = [NSMutableArray arrayWithObjects:@"景点", @"住宿", @"餐厅", @"休闲娱乐", @"购物", nil];
    
    
    for (NSInteger i = 0; i < self.titleArr.count; i ++) {
        UIButton *button = [UIButton buttonWithType:UIButtonTypeSystem];
        [menu addSubview:button];
        button.tag = 1000+i;
        button.frame = CGRectMake( (ScreenWidth / 5) * i + 5, 8, ScreenWidth/5-12, menu.frame.size.height-10);
        button.backgroundColor = [UIColor colorWithRed:44 / 255.0 green:165 / 255.0 blue:246 / 255.0 alpha:1];
        [button.layer setMasksToBounds:YES];
        [button.layer setCornerRadius:14];
        [button.titleLabel setFont:[UIFont fontWithName:@"AppleGothic" size:10]];
        [button setTitle:[self.titleArr objectAtIndex:i] forState:UIControlStateNormal];
        [button addTarget:self action:@selector(buttonClick:) forControlEvents:UIControlEventTouchUpInside];
        [button setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        if (i == 0) {
            [button setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
            button.backgroundColor = [UIColor colorWithRed:44 / 255.0 green:165 / 255.0 blue:246 / 255.0 alpha:1];
        }
        
        [self.buttonArr addObject:button];
    }
    
    
    
}

#pragma mark - 菜单点击方法
- (void)buttonClick:(UIButton *)button
{
    NSLog(@"%ld", button.tag);
}


#pragma mark - 创建collectionView
- (void)creatCollectionView
{
    UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];
    layout.itemSize = CGSizeMake(self.view.frame.size.width, self.view.frame.size.height - 40);
    layout.sectionInset = UIEdgeInsetsMake(0, 0, 0, 0);
    layout.scrollDirection = UICollectionViewScrollDirectionHorizontal;
    layout.minimumLineSpacing = 0;
    layout.minimumInteritemSpacing = 0;
    
    self.collectionView = [[UICollectionView alloc] initWithFrame:CGRectMake(0, 40, ScreenWidth, ScreenHeight) collectionViewLayout:layout];
    self.collectionView.delegate = self;
    self.collectionView.backgroundColor = [UIColor whiteColor];
    
    self.collectionView.dataSource = self;
    [self.collectionView registerClass:[TourPlaceCollectionViewCell class] forCellWithReuseIdentifier:@"twoCell"];
    
    
    [self.collectionView registerClass:[UICollectionReusableView class] forSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@"header"];
    
    self.collectionView.contentSize = CGSizeMake(self.view.frame.size.width, self.view.frame.size.height);

    
    self.collectionView.pagingEnabled = YES;
    
    [self.view addSubview:self.collectionView];
    
    [self creatScrollView];
    
}

#pragma mark - collectionView方法
#pragma mark - 点击方法
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
{
    [collectionView deselectItemAtIndexPath:indexPath animated:YES];
    

}

#pragma mark - cell个数
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
    
    
    return 4;
}

#pragma mark - cell内容
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
    TourPlaceCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"twoCell" forIndexPath:indexPath];
    
    cell.backgroundColor = [UIColor grayColor];
    
    return cell;
    
}

#pragma mark - 嵌套的TableView的协议方法

#pragma mark - cell内容
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    TourPlaceTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell"];
    
    cell.backgroundColor = [UIColor redColor];
    
    return cell;
}

#pragma mark - cell的大小
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 200;
}

#pragma mark - 点击方法
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    
}

#pragma mark - cell的个数
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return 5;
}




@end
